import { useEffect, useState } from "react"

function useScrollPosition() {
  const [scroll, setScroll] = useState(0);

  useEffect(() => {
    const handleScroll = () => {
      setScroll(window.scrollY)
    }
    
    document.addEventListener("scroll", handleScroll);
    
    return () => {
      document.removeEventListener("scroll", handleScroll);
    }
  }, [])

  return scroll;
}

export default useScrollPosition